package com.zx.mobile.controller;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alipay.api.AlipayApiException;
import com.zx.map.dao.model.ActiveRedpacket;
import com.zx.map.dao.model.Redpacket;
import com.zx.map.service.OrdLogService;
import com.zx.map.service.model.MerchantInfoDetailModel;
import com.zx.map.service.model.OrdLogModel;
import com.zx.map.utils.CommonResponseUtils;
import com.zx.mobile.utils.WebUtils;
import com.zx.platform.utils.AlipayUtil;

@Controller
@RequestMapping("/trade")
public class TradeController {

	@Autowired
	private OrdLogService ordLogService;
	
	@RequestMapping("/tradeInfo")
	@ResponseBody
	public Map tradeInfo(@RequestBody Map<String, Object> params, HttpServletRequest request) {
		try {
			MerchantInfoDetailModel merchant = WebUtils.queryCurrentLoginMerchantInfoDetailModel(request);
			params.put("merchantId", merchant.getMerchantId());
			Map<String, Object> result = ordLogService.tradeInfo(params);
			return CommonResponseUtils.successResponse(result);
		}catch(Exception e ) {
			e.printStackTrace();
			return CommonResponseUtils.failureResponse(e.getMessage());
		}
	}
	
	@RequestMapping("/tradeAnalysis")
	@ResponseBody
	public Map tradeAnalysis(@RequestBody Map<String, Object> params, HttpServletRequest request) {
		try {
			MerchantInfoDetailModel merchant = WebUtils.queryCurrentLoginMerchantInfoDetailModel(request);
			params.put("merchantId", merchant.getMerchantId());
			Map<String, Object> result = ordLogService.groupbyType(params);
			
			return CommonResponseUtils.successResponse(result);
		}catch(Exception e ) {
			e.printStackTrace();
			return CommonResponseUtils.failureResponse(e.getMessage());
		}
	}
	
	@RequestMapping("priceRange")
	@ResponseBody
	public Map priceRange(@RequestBody Map<String, Object> params, HttpServletRequest request) {
		try {
			MerchantInfoDetailModel merchant = WebUtils.queryCurrentLoginMerchantInfoDetailModel(request);
			params.put("merchantId", merchant.getMerchantId());
			List<Map<String, Object>> result = ordLogService.priceRange(params);
			return CommonResponseUtils.successResponse(result);
		}catch(Exception e ) {
			e.printStackTrace();
			return CommonResponseUtils.failureResponse(e.getMessage());
		}
	}

}
